﻿/*
==================================================================
    注意：此文件为Auto代码，不可手动修改【仓库管理员】
==================================================================
*/

namespace Services
{
    /// <summary>
    /// Auto仓库管理员
    /// </summary>
    public abstract class AutoWarehouseUserMapping : BaseMapping<WarehouseUser, WarehouseUserModel, WarehouseUserFilterModel>
    {
        public AutoWarehouseUserMapping(ICurrentUser currentUser)
            : base(currentUser) { }

        #region 读数据
        /// <summary>
        /// 读数据，从Entity对象转成Model对象
        /// </summary>
        /// <param name="entity">Entity对象</param>
        /// <returns></returns>
        public override WarehouseUserModel Entity2Model(WarehouseUser entity)
        {
            WarehouseUserModel model = new WarehouseUserModel();

            model.WarehouseUserID = entity.WarehouseUserID;
            model.GroupInfoID = entity.GroupInfoID;
            model.WarehouseID = entity.WarehouseID;
            model.UserID = entity.UserID;

            return model;
        }
        #endregion

        #region 写数据
        /// <summary>
        /// 写数据，从Model对象转换成Entity对象
        /// </summary>
        /// <param name="model">ViewModel对象</param>
        /// <returns></returns>
        public override WarehouseUser Model2Entity(WarehouseUserModel model)
        {
            WarehouseUser entity = new WarehouseUser();

            entity.WarehouseUserID = model.WarehouseUserID;
            entity.GroupInfoID = model.GroupInfoID;
            entity.WarehouseID = model.WarehouseID;
            entity.UserID = model.UserID;

            return entity;
        }
        #endregion

        #region 搜索条件转换
        /// <summary>
        /// 搜索条件转换，从FilterModel对象转换成Where对象
        /// </summary>
        /// <param name="filterModel">FilterModel对象</param>
        /// <returns></returns>
        public override Expressionable<WarehouseUser> FilterModel2Where(WarehouseUserFilterModel filterModel)
        {
            var where = base.FilterModel2Where(filterModel);

            //编号
            if (filterModel._WarehouseUserID.HasValue)
            {
                where = where.And(x => x.WarehouseUserID == filterModel._WarehouseUserID.Value);
            }
            if (filterModel._WarehouseUserIDs.IsNotEmpty() && filterModel._WarehouseUserIDs.Count > 0)
            {
                where = where.And(x => filterModel._WarehouseUserIDs.Contains(x.WarehouseUserID));
            }
            if (filterModel._NotWarehouseUserIDs.IsNotEmpty() && filterModel._NotWarehouseUserIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotWarehouseUserIDs.Contains(x.WarehouseUserID));
            }

            //集团
            if (filterModel._GroupInfoID.HasValue)
            {
                where = where.And(x => x.GroupInfoID == filterModel._GroupInfoID.Value);
            }
            if (filterModel._GroupInfoIDs.IsNotEmpty() && filterModel._GroupInfoIDs.Count > 0)
            {
                where = where.And(x => filterModel._GroupInfoIDs.Contains(x.GroupInfoID));
            }
            if (filterModel._NotGroupInfoIDs.IsNotEmpty() && filterModel._NotGroupInfoIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotGroupInfoIDs.Contains(x.GroupInfoID));
            }

            //仓库
            if (filterModel._WarehouseID.HasValue)
            {
                where = where.And(x => x.WarehouseID == filterModel._WarehouseID.Value);
            }
            if (filterModel._WarehouseIDs.IsNotEmpty() && filterModel._WarehouseIDs.Count > 0)
            {
                where = where.And(x => filterModel._WarehouseIDs.Contains(x.WarehouseID));
            }
            if (filterModel._NotWarehouseIDs.IsNotEmpty() && filterModel._NotWarehouseIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotWarehouseIDs.Contains(x.WarehouseID));
            }

            //用户
            if (filterModel._UserID.HasValue)
            {
                where = where.And(x => x.UserID == filterModel._UserID.Value);
            }
            if (filterModel._UserIDs.IsNotEmpty() && filterModel._UserIDs.Count > 0)
            {
                where = where.And(x => filterModel._UserIDs.Contains(x.UserID));
            }
            if (filterModel._NotUserIDs.IsNotEmpty() && filterModel._NotUserIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotUserIDs.Contains(x.UserID));
            }

            return where;
        }
        #endregion
    }
}

